<?php
if (!function_exists('viewByTemplate'))
{
	function viewByTemplate($view, $data=NULL, $templateFileName='', $theme = '')
	{
		global $template,$default_title;
		
		if($templateFileName=='') $templateFileName = 'index';
		if(count($data)>0 && array_key_exists('title',($data==NULL?array():$data)) && $data['title']!=''){
			$data['title_for_layout'] = $data['title'];
		}else{
			$data['title_for_layout'] = $default_title;
		}
		
		$ci = &get_instance();
		$data['content_for_layout'] = $ci->load->view($view, $data, true);
		
		if(@strstr($templateFileName,'.')!='') $templateFileName = $templateFileName.'.php';
		
		$file_path	= 'templates/'.($theme!=''?$theme:$template).'/'.$templateFileName;
		if(!file_exists(APPPATH.'views/'.$file_path.'.php')){
			$file_path	= 'templates/standard/'.$templateFileName;
		}
		echo $ci->load->view($file_path, $data, true);
	}
}
?>